﻿using UnityEngine;

namespace ProjectMyFarmAndShe
{
    public class AddThirdSeries
    {
        public static void AddChallenge(ChallengeSeries series)
        {
            var emailSystem = Global.Interface.GetSystem<IEmailSystem>();
            var toolBarSystem = Global.Interface.GetSystem<IToolbarSystem>();
            
            var firstChallenge = new ChallengeData()
                .WithKey("路边摊的王大妈第一个的委托")
                .WithPublisher("路边摊的王大妈")
                .WithDescription("最近供应商出了点问题不能即使提供货物,能提供我二十个土豆吗")
                .WithUnlock((self) => true)
                .WithCondition(() =>
                {
                    if (Global.PotatoCount.Value >= 20)
                    {
                        return true;
                    }

                    return false;
                })
                .WithFinishedAction((self) =>
                {
                    Global.PotatoCount.Value -= 20;
                    toolBarSystem.SubToolbarData("Potato", 20);
                    
                    Global.Coin.Value += 60;
                    
                    var emailData = new EmailData()
                        .WithTitle($"{self.Publisher}第{self.FinishedDay}天的感谢信")
                        .WithPublisher(self.Publisher)
                        .WithInfo("最近供货商们的收成不太好,他们又负责了很多人商位,所以这次能给到我的土豆非常少。所以我从工会打听到了你所以找到了你" +
                                  "你的土豆质量非常好,我就在想以后要不要就找你当我的供货商了哈哈。")
                        .WithSendDay(self.FinishedDay + 1)
                        .WithRead(false);

                    emailSystem.AddEmail(emailData);
                    
                    MessagePanel.Default.AddMessage($"{self.Key}完成");
                });
            
            var secondChallenge = new ChallengeData()
                .WithKey("路边摊的王大妈第二个的委托")
                .WithPublisher("路边摊的王大妈")
                .WithDescription("提供十个土豆和二十个萝卜")
                .WithUnlock((self) =>
                {
                    if (firstChallenge.Finished && Global.Day.Value > firstChallenge.FinishedDay + 2)
                    {
                        return true;
                    }

                    return false;
                })
                .WithCondition(() =>
                {
                    if (Global.PotatoCount.Value >= 10 && Global.TurnipCount.Value >= 20)
                    {
                        return true;
                    }

                    return false;
                })
                .WithFinishedAction((self) =>
                {
                    Global.PotatoCount.Value -= 10;
                    Global.TurnipCount.Value -= 20;
                    toolBarSystem.SubToolbarData("Potato", 10);
                    toolBarSystem.SubToolbarData("Turnip", 20);
                    
                    Global.Coin.Value += 150;
                    
                    var emailData = new EmailData()
                        .WithTitle($"{self.Publisher}第{self.FinishedDay}天的感谢信")
                        .WithPublisher(self.Publisher)
                        .WithInfo("上次的土豆用完了,然后原来的供货商提供了一些土豆,但是顾客反应没有之前的好吃。所以这次用来找你进货了,顺带想了解你其他的物品怎么样,没想到顾客反应十分的好。" +
                                  "所以下次我用完了之后我又来找你进货了,觉得不会亏待你的,哈哈")
                        .WithSendDay(self.FinishedDay + 1)
                        .WithRead(false);

                    emailSystem.AddEmail(emailData);
                    
                    MessagePanel.Default.AddMessage($"{self.Key}完成");
                });
            
            var thirdChallenge = new ChallengeData()
                .WithKey("路边摊的王大妈第二个的委托")
                .WithPublisher("路边摊的王大妈")
                .WithDescription("提供十个土豆和十个萝卜和十个粉色萝卜")
                .WithUnlock((self) =>
                {
                    if (secondChallenge.Finished && Global.Day.Value > secondChallenge.FinishedDay + 2)
                    {
                        return true;
                    }

                    return false;
                })
                .WithCondition(() =>
                {
                    if (Global.PotatoCount.Value >= 10 && Global.TurnipCount.Value >= 10 && Global.PinkRadishCount.Value >= 10)
                    {
                        return true;
                    }

                    return false;
                })
                .WithFinishedAction((self) =>
                {
                    Global.PotatoCount.Value -= 10;
                    Global.TurnipCount.Value -= 10;
                    Global.PinkRadishCount.Value -= 10;
                    toolBarSystem.SubToolbarData("Potato", 10);
                    toolBarSystem.SubToolbarData("Turnip", 10);
                    toolBarSystem.SubToolbarData("PinkRadish", 10);
                    
                    Global.Coin.Value += 300;
                    
                    var emailData = new EmailData()
                        .WithTitle($"{self.Publisher}第{self.FinishedDay}天的感谢信")
                        .WithPublisher(self.Publisher)
                        .WithInfo("果然找你进货是十分正确的选择,上次那批货没过几天就卖完了,我休息了几天还被老顾客追着问啥时候开张,所以就又找上了你,哈哈。期待下次的合作,报酬肯定少不了你的。")
                        .WithSendDay(self.FinishedDay + 1)
                        .WithRead(false);

                    emailSystem.AddEmail(emailData);
                    
                    MessagePanel.Default.AddMessage($"{self.Key}完成");
                });

            series.AddChallenge(firstChallenge)
                .AddChallenge(secondChallenge)
                .AddChallenge(thirdChallenge);
        }
    }
}